﻿<?php
	/* if parent of category is uncategory, current view category is yours*/
	/* get current category by using $cat*/
	$currentParentCategory = get_category($cat)->parent;
	$currentParentCategory = $currentParentCategory == 0 ? $cat : $currentParentCategory;
	
	$bFirst = false;
	/* if user clicks on the post permanent link, the $cat will be empty. In this situation, we have to get the category ID to which a post is belong to*/
	if ( empty( $cat ) ) {
		$list_categories = get_the_category( $post->ID ) ;
		
		foreach ( $list_categories as $category ) {
			if ( $category->slug != 'hot-news' ) {
				$currentParentCategory = $category->parent;
				$currentParentCategory = $currentParentCategory == 0 ? $category->cat_ID : $currentParentCategory;
				$currentViewCateogry = $category->cat_ID;
			}
		}
		unset ( $category );
	}
	else {
		$bFirst = $currentParentCategory == $cat ? true : false; // hack for current <li>
		$currentViewCateogry = $cat;
	}
?>
<div id="content_left">
	<div id="content_left_up">
		<div id="title_list_menu"><?php echo get_category($currentParentCategory)->name; ?></div>
		<div id="list_menu_center">
			<?php
			/* list all sub-categories*/
			$args = array( 'parent' => $currentParentCategory, 'hide_empty' => false );

			$cat_data = get_category( $currentParentCategory );
			if ( $cat_data->slug == 'diem-ban') {
				$args = array( 'parent' => $currentParentCategory, 'hide_empty' => false, 
								'orderby' => 'id', 'order' => 'ASC' );
			}
			wp_reset_postdata();
			$categories = get_categories( $args );
			foreach ( $categories as $category ) : 
				$link = get_category_link( $category->term_id );
				if ( $category->category_description == 'one_post' ) :
					$args=array(
						'cat' => $category->cat_ID,
						'post_type' => 'post',
						'post_status' => 'publish',
						'posts_per_page' => 1
					);
					$my_query = new WP_Query($args);
					
					if( $my_query->have_posts() ) {
						while ($my_query->have_posts()) :
							$my_query->the_post();
							$link = get_permalink();
						endwhile;
					}
					wp_reset_postdata();
				endif;
			?>
			<div class="class_menu" style="margin-top: 20px; width:90%;">
				<div class="menu_father_one">
					<?php if ( $currentViewCateogry == $category->cat_ID || $bFirst ): $bFirst = false ?>
					<span style="margin-left:-10px; border-bottom:1px solid #161616">
						<a href="<?php echo $link ?> ">» <?php _e($category->name); ?></a>
					</span>
					<?php else: ?>
					<span style="">
						<a href="<?php echo $link ?> "><?php _e($category->name); ?></a>
					</span>				
					<?php endif ?>
				</div>							
				<div class="content_father_one">
					<ul></ul>
				</div>
			</div>
			<?php endforeach; ?>
			<div class="clear"></div>									
		</div>					
	</div>
	<div id="content_left_down" style="float:left;">
		<div id="content_left_down" style="float:left;">
			<marquee onmouseover="this.stop();" onmouseout="this.start();" behavior="scroll" direction="left" scrollamount="3" style="float:left; height:63px">
				<a href="#" target="_blank" class="arg_operations" title="Đối tác IMC"><img src="#" width="auto" height="63" title="Đối tác IMC Đối tác 1"/></a>
<a href="#" target="_blank" class="arg_operations" title="Đốit tác VIDS"><img src="#" width="auto" height="63" title="Đốit tác VIDS Đối tác 2"/></a>
<a href="#" target="_blank" class="arg_operations" title="Công ty Bio Sunz"><img src="#" width="auto" height="63" title="Công ty Bio Sunz Đối tác 3"/></a>
			</marquee>
		</div>
	</div>
</div>